import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-16
 * Time: 1:47
 */
//https://leetcode.cn/problems/longest-substring-without-repeating-characters/
public class Test {
    public static int lengthOfLongestSubstring(String s) {
        HashSet set = new HashSet();
        int max = 0;
        int n = 0;
        int p1 = 0;
        int p2 = 0;
        int len = s.length();
        while (p2 < len)
            if (set.contains(s.charAt(p2))) {
                set.remove(s.charAt(p1++));
                n--;
            } else {
                set.add(s.charAt(p2++));
                n++;
                max = Math.max(max, n);
            }
        return max;
    }
    public static void main(String[] args) {
        String str="sadw 1j23njkdna";
        System.out.println(lengthOfLongestSubstring(str));
    }
}
